package com.itr.kbm.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.itr.kbm.dao.EmployeeDao;
import com.itr.kbm.model.Employee;

@Repository
public class EmployeeDaoImpl extends AbstractDaoImpl<Employee, String> implements EmployeeDao {

	Logger logger = Logger.getLogger(this.getClass());
	
    protected EmployeeDaoImpl() {
        super(Employee.class);
    }
    
    public String checkEmployeeToDB(String nik, String nama) {
          	
    	Criteria criteria = getCurrentSession().createCriteria(Employee.class);
    	criteria.add(Restrictions.eq("nik", nik));
    	List<Employee> listEmployee = criteria.list();
    	
    	if (listEmployee.size() == 0) {
    		return "false";
    	}
    	else { 
    		if ((listEmployee.get(0).getNik().equals(nik)) && (listEmployee.get(0).getNama().equals(nama))) {  	
    			return "true";
    		}
    	}
    	
    	return "false";
	}
    
    public List<Employee> getAllEmployee() {
      	
    	Criteria criteria = getCurrentSession().createCriteria(Employee.class);
    	criteria.add(Restrictions.isNotNull("nik"));
    	List<Employee> listEmployee = criteria.list();
    	    	
    	return listEmployee;
	}
	
}
